package com.zlcx.tz.live.common.config;

import feign.RequestTemplate;
import feign.codec.EncodeException;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.web.multipart.MultipartFile;
import java.lang.reflect.Type;

/**
 * <p></p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author zl
 * @version 1.0
 * @date Created in 2019/11/7 18:27
 * @copyright: Copyright (c) founders
 */

public class FeignSpringFormEncoder extends SpringFormEncoder {

    private Encoder delegate;

    public FeignSpringFormEncoder() {
        super();
    }

    public FeignSpringFormEncoder(Encoder delegate) {
        super(delegate);
        this.delegate = delegate;
    }

    @Override
    public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
        if (!bodyType.equals(MultipartFile.class)) {
            delegate.encode(object, bodyType, template);
        } else {
            super.encode(object, bodyType, template);
        }
    }


}
